<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='./vue.js'></script>
</head>

<body>
    <div id='app'>
        <button @click="btnClick" :disabled="time < 10"> {{text}} </button>
    </div>
</body>
<script>
    const app = {
        data() {
            return {
                text: '发送验证码',
                time: 10,
                t: null
            }
        },
        methods: {
            btnClick() {
                clearInterval(this.t)

                this.t = setInterval(() => {
                    this.text = this.time
                    this.time--
                    if (this.time == 0) {
                        clearInterval(this.t)
                        this.text = '重新获取'
                        this.time = 10
                    }
                }, 1000)
            }
        },
    }
    const vm = Vue.createApp(app).mount('#app')
</script>

</html>